import Vue from 'vue'
import xurl from '../../x/xurl'
import store from '../../store'

export default {
    /**
     * 打开单件活动
     * @param singleActId
     */
    openSingleAct(singleActId) {
        let url = Vue.prototype.NW_API_vue + "/union/single/activity/" + singleActId + "/page/open"
        xurl.getLoading(url).then(data => {
            if (data.success) {
                window.location.href = data.result.redirect;
            } else {
                window.location.href =  "/error?msg=" + data.errMsg
            }
        })
    },
    /**
     * 去普通商品頁面
     * @param toItemDetail
     */
    toItemDetail(itemId,random4Num) {
        if (store.state.xPreview) {
            // console.log('预览页不可操作。');
        } else {
            window.location.href =  '/item/' + itemId + '/detail/' + Math.random().toString(36).substr(2).slice(1, 5);;
        }
    },
    /**
     * 去门店主页
     * @param toHome
     */
    toHome(storeId) {
        if (store.state.xPreview) {
            // console.log('预览页不可操作。');
        } else {
            // this.$router.push({path: '/to/store', query: {storeId: this.item.storeId}})
            window.location.href =  '/store?storeId='+storeId;
        }
    },
    /**
     * 去營銷活动頁面
     * @param toMarketing
     */
    toMarketing(marketingId) {
        if (store.state.xPreview) {
            // console.log('预览页不可操作。');
        } else {
            window.location.href =  '/act/marketing/' + marketingId + '/detail';
        }
    }
}